import wx from './wx'
import { Storetoken } from './wxstore'
import Dialog from '@vant/weapp/dist/dialog/dialog'

export const checkSession = async () => {
  try {
    await wx.checkSession()
    return true
  } catch (error) {
    return false
  }
}
export const confirmAuth = () => {
  Dialog.confirm({
    title: '登录',
    message: '你还没有登录，确定登录吗'
  })
    .then(() => {
      wx.navigateTo({ url: '/pages/login/main' })
    })
    .catch(() => {
      console.log('cancle')
    })
}

export const checkAuth = async () => {
  const token = await Storetoken.get()
  if (token) {
    const flag = await checkSession()
    if (flag) {
      return true
    }
  }
  return false
}
